package com.totoro.service;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.totoro.dao.BaseHibernateDao;
import com.totoro.dao.StaffDao;
import com.totoro.domain.Department;
import com.totoro.domain.Staff;
import com.totoro.domain.Staff;
import com.totoro.util.Page;

/*
 * 校内员工service
 */
@Transactional
@Service
public class StaffService extends BaseService<Staff, Integer>{

	private StaffDao staffDao;
	
	@Autowired
	@Override
	public void setBaseDao(BaseHibernateDao<Staff, Integer> staffDao) {
		// TODO Auto-generated method stub
		this.baseDao = staffDao;
		this.staffDao = (StaffDao) staffDao;
	}
	
	//分页查询通过页号
	public Page<Staff> getPagePosts(Integer pageNo,int pageSize){
		Criteria criteria = staffDao.createCriteria();
//		criteria.
		return staffDao.pagedQuery(criteria, pageNo, pageSize);
	}
	
	//分页查询:通过页号、教研室
	public Page<Staff> getPagePostsByDepartment(Integer pageNo,int pageSize,Department department){
		Criteria criteria = staffDao.createCriteria();
		criteria.add(Restrictions.eq("department", department));
		return staffDao.pagedQuery(criteria, pageNo, pageSize);
	}
}
